package com.zjj.juc;

/**
 * @author zhoujunjie
 * @desc TODO
 * @date
 */
import java.util.concurrent.CountDownLatch;

public class Test1 {
    public static void main(String[] args) {
        CountDownLatch latch = new CountDownLatch(1);

        Thread thread1 = new Thread(() -> {
            try {
                System.out.println("A");
                latch.await();
                System.out.println("C");
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        });

        Thread thread2 = new Thread(() -> {
            try {
                Thread.sleep(3000);
                System.out.println("B");
                latch.countDown();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        });

        thread1.start();
        thread2.start();

        try {
            thread1.join();
            thread2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}